#{extends 'site.html' /}
#{set title:'Profile' /}

<h2>Profile</h2>

#{form @Profiles.save()}
   
    <p class="bloc_line">
        <label for="firstname">First name: </label>
        <input type="text" name="firstname" id="firstname" value="${user.firstname}" />
        <span class="error">#{error 'firstname' /}</span>
    </p>
    <p class="bloc_line">
        <label for="lastname">Last name: </label>
        <input type="text" name="lastname" id="lastname" value="${user.lastname}" />
        <span class="error">#{error 'lastname' /}</span>
    </p>
    <p class="bloc_line">
        <label for="email">Email: </label>
        <input type="text" name="email" id="email" value="${user.email}" disabled="disabled"/>
    </p>
    <p class="bloc_line">
        <label for="password">Password: </label>
        <input type="password" name="password" id="password" value="${user.password}" />
        <span class="error">#{error 'password' /}</span>
    </p>
    <p class="bloc_line">
        <label for="confirm_password">Confirm password: </label>
        <input type="password" name="confirm_password" id="confirm_password" value="${user.password}" />
        <span class="error">#{error 'confirm_password' /}</span>
    </p>
    <p class="bloc_line">
        <label for="birthdate">Birth date: </label>
        <input type="text" name="birthdate" id="birthdate"  value="${user.birthdate}"/>
        <span class="error">#{error 'birthdate' /}</span>
    </p>
    #{if user.profile != null}
    <p class="bloc_line">
        <label for="profile">Profile: </label>
        <input type="text" name="profile" id="profile"  value="${user.profile}" disabled="disabled"/>
    </p>
    #{/if}
    #{if creditable}
	    <p class="bloc_line">
	        <label for="credit">Credit: </label>
	        <input type="text" name="credit" id="credit"  value="${user.credit}" disabled="disabled"/><span class="info"> units</span>
	    </p>
	    <ul class="addingCredit">
			<li>
				<a href="#" onclick="credit()">Add credit</a>
			</li>
		</ul>
    #{/if}

    <script type="text/javascript">
    
	    function credit() {
	    	var creditAction = #{jsAction @Profiles.addCredit(':sum') /};
	    	
	    	$.post(creditAction({sum:10}),null,function(userCredit){
	    		// Load into input#credit
	    		$('#credit').val(userCredit);
	    		alert("Free version : Add 10 units")
	    	});
	    }
	    
    </script>
    
    <p class="bloc_line">
        <input type="submit" value="Save" />
    </p>
#{/form}
